<template>
  <div>
    <tableComponents
      :pagination="{ currentPage, pageSize, total: list.all_num }"
      @handleCurrentChange="handleCurrentChange"
      @handleSizeChange="handleSizeChange"
      @sendUserSearch="receive_search"
      :searchData="searchDataInfo"
      :isHaveExport="false"
      @toAdd="openAdd"
    >
      <template v-slot:table>
        <el-table
          ref="multipleTable"
          :data="list.data"
          stripe
          v-loading="tableLoading"
          header-row-class-name="head_color"
          tooltip-effect="dark"
          style="width: 99.8%"
          @selection-change="handleSelectionChange"
        >
          <!-- <el-table-column type="selection" class="tc" width="35"></el-table-column> -->
          <el-table-column
            prop="sort"
            sortable
            :sort-method="sorta"
            label="排序"
            min-width="50"
          >
            <template slot-scope="scope">
              <el-input
                @change="sortNew(scope.$index, scope.row)"
                v-model.number="scope.row.sort"
                autocomplete="off"
                size="mini"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="头像" min-width="80">
            <template slot-scope="scope">
              <div class="img_bor_tx">
                <img :src="$fnc.getImgUrl(scope.row.avatar)" alt />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="用户信息" min-width="120">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>用户昵称：</span>
                  <span>{{ scope.row.nickname || "----" }}</span>
                </div>
                <div>
                  <span>会员账号：</span>
                  <span>{{ scope.row.username || "---" }}</span>
                </div>
                <div>
                  <span>姓名：</span>
                  <span>{{ scope.row.name || "---" }}</span>
                </div>
                <div>
                  <span>上下班状态：</span>
                  <span>{{
                    scope.row.is_work == 1 ? "上班" : "下班" || "---"
                  }}</span>
                </div>
                <div>
                  <span>添加时间：</span>
                  <span>{{ scope.row.created_time | getTimeFormat }}</span>
                </div>
                <div>
                  <span>修改时间：</span>
                  <span>{{ scope.row.update_time | getTimeFormat }}</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="师傅信息" min-width="120">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>联系电话：</span>
                  <span>{{ scope.row.tel || "----" }}</span>
                </div>
                <div>
                  <span>紧急联系人电话：</span>
                  <span>{{ scope.row.urgent || "---" }}</span>
                </div>
                <div>
                  <span>身份证：</span>
                  <span>{{ scope.row.cardid || "---" }}</span>
                </div>
                <div>
                  <span>岗位：</span>
                  <span>{{ scope.row.station || "---" }}</span>
                </div>
                <div>
                  <span>生日：</span>
                  <span>{{ scope.row.birthday | getTimeFormat2 }}</span>
                </div>
                <div>
                  <span>从业日期：</span>
                  <span>{{ scope.row.employment | getTimeFormat2 }}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="师傅信息" min-width="120">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>入驻城市：</span>
                  <span
                    >{{ scope.row.province }}{{ scope.row.city
                    }}{{ scope.row.area }}{{ scope.row.town }}</span
                  >
                </div>
                <div>
                  <span>常驻地址：</span>
                  <span>{{ scope.row.add || "---" }}</span>
                </div>
                <div>
                  <span>今日接单限额：</span>
                  <span>{{
                    scope.row.quota == 0 ? "不限" : scope.row.quota
                  }}</span>
                </div>
                <div>
                  <span>平台佣金：</span>
                  <span>{{ Number(scope.row.fee) || "---" }}‰</span>
                </div>
                <div>
                  <span>标签：</span>
                  <span>{{ scope.row.label || "---" }}</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="是否上岗" min-width="65">
            <template slot-scope="scope">
              <el-switch
                class="zdySwith"
                :width="82"
                v-model="scope.row.show"
                active-color="#1aad19"
                inactive-color="#ffffff"
                active-text="on"
                inactive-text="off"
                active-value="1"
                @change="handleSwitch($event, scope.row)"
                inactive-value="0"
              ></el-switch>
            </template>
          </el-table-column>

          <el-table-column label="操作" min-width="120">
            <template slot-scope="scope">
              <el-row class="myblank">
                <el-button
                  :loading="$store.state.isLoading"
                  size="mini"
                  @click="openDetail(scope.row)"
                  type="primary"
                  >更多信息</el-button
                >
                <el-button
                  :loading="$store.state.isLoading"
                  size="mini"
                  @click="openOrder(scope.row)"
                  type="primary"
                  >查看订单</el-button
                >
                <el-button
                  :loading="$store.state.isLoading"
                  size="mini"
                  type="success"
                  @click="openArea(scope.row)"
                  >师傅区域</el-button
                >
                <el-button
                  :loading="$store.state.isLoading"
                  size="mini"
                  type="success"
                  @click="openCate(scope.row)"
                  >师傅品类</el-button
                >
                <el-button
                  :loading="$store.state.isLoading"
                  size="mini"
                  type="warning"
                  @click="openEdit(scope.row)"
                  >编辑</el-button
                >
                <el-button
                  :loading="$store.state.isLoading"
                  size="mini"
                  type="danger"
                  @click="openDelete(scope.row.id)"
                  >删除</el-button
                >
              </el-row>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <template v-slot:footerLeft> </template>
    </tableComponents>

    <el-dialog
      :close-on-click-modal="false"
      :title="isEdit ? '编辑' : '添加'"
      class="tl size_13"
      width="1200px"
      :visible.sync="dialogFormVisible"
    >
      <el-form :model="edit_data" ref="form" label-width="160px">
        <el-form-item label="选择用户：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              disabled
              placeholder="请输入"
              v-model="edit_data.username"
              autocomplete="off"
            ></el-input>
          </el-col>
          <el-col :span="4" :offset="1" v-if="!isEdit">
            <el-button
              :loading="$store.state.isLoading"
              size="medium"
              type="primary"
              @click="xzshop('xzuser')"
              >选择用户</el-button
            >
          </el-col>
        </el-form-item>
        <el-form-item label="真实姓名：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入"
              v-model="edit_data.name"
              autocomplete="off"
            ></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="入驻城市">
          <el-col :span="12" v-if="dialogFormVisible">
            <city-cascader
              :level="1"
              size="large"
              :placeholder="selectedOptions.join('-')"
              @change="handleChange"
            />
          </el-col>
        </el-form-item>

        <el-form-item label="常驻地址：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入"
              v-model="edit_data.add"
              autocomplete="off"
            ></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="常驻地址经纬度：">
          <el-col :span="12">
            <el-input placeholder="请输入" v-model="czJWD" clearable>
              <template slot="append">
                <a
                  target="_blank"
                  :href="'https://lbs.qq.com/tool/getpoint/index.html'"
                >
                  <el-button :loading="$store.state.isLoading" size="mini"
                    >查看经纬度</el-button
                  >
                </a>
              </template>
            </el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="真人照片：" prop="avatar">
          <el-col :span="12">
            <el-input v-model="edit_data.avatar" disabled></el-input>
            <uploadpic
              :piclink="edit_data.avatar"
              :width="200"
              :height="200"
              :real_width="200"
              :real_height="200"
              :is_more="false"
              @send_pic="onSuccess($event, 3)"
            ></uploadpic>
          </el-col>
        </el-form-item>
        <el-form-item label="联系电话：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入"
              v-model="edit_data.tel"
              autocomplete="off"
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="紧急联系人电话：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入"
              v-model="edit_data.urgent"
              autocomplete="off"
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="身份证：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入"
              v-model="edit_data.cardid"
              autocomplete="off"
            ></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="带头像的身份证照：">
          <el-col :span="12">
            <el-input v-model="edit_data.cardid1"></el-input>
            <uploadpic
              :piclink="edit_data.cardid1"
              :width="200"
              :height="200"
              :real_width="200"
              :real_height="200"
              :is_more="false"
              @send_pic="onSuccess($event, 4)"
            ></uploadpic>
          </el-col>
        </el-form-item>

        <el-form-item label="带国徽的身份证照：">
          <el-col :span="12">
            <el-input v-model="edit_data.cardid2"></el-input>
            <uploadpic
              :piclink="edit_data.cardid2"
              :width="200"
              :height="200"
              :real_width="200"
              :real_height="200"
              :is_more="false"
              @send_pic="onSuccess($event, 5)"
            ></uploadpic>
          </el-col>
        </el-form-item>

        <el-form-item label="岗位：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入"
              v-model="edit_data.station"
              autocomplete="off"
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="生日：">
          <el-col :span="12">
            <el-date-picker
              v-model="edit_data.birthday"
              type="date"
              value-format="timestamp"
            ></el-date-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="从业日期：">
          <el-col :span="12">
            <el-date-picker
              v-model="edit_data.employment"
              type="date"
              value-format="timestamp"
            ></el-date-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="今日接单限额：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入"
              v-model="edit_data.quota"
              autocomplete="off"
            >
              <span slot="append">0表示不限</span>
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="平台佣金：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入"
              v-model="edit_data.fee"
              autocomplete="off"
            >
              <span slot="append">‰</span>
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="标签：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入"
              v-model="edit_data.label"
              autocomplete="off"
            >
              <span slot="append">@间隔</span>
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="个人介绍：">
          <el-col :span="12">
            <el-input
              type="textarea"
              resize="none"
              :rows="3"
              placeholder="请输入"
              v-model="edit_data.introduce"
            />
          </el-col>
        </el-form-item>
        <el-form-item label="个人介绍图片" prop="introduce_piclink_arr">
          <el-col :span="12">
            <uploadpic
              :file="edit_data.introduce_piclink_arr"
              :width="150"
              :height="150"
              :real_width="150"
              :real_height="150"
              :is_more="true"
              @send_pic="onSuccess($event, 1)"
              @del_pic="edit_data.introduce_piclink_arr.splice($event, 1)"
            ></uploadpic>
          </el-col>
        </el-form-item>
        <el-form-item label="证书" prop="certificate_arr">
          <el-col :span="12">
            <uploadpic
              :file="edit_data.certificate_arr"
              :width="150"
              :height="150"
              :real_width="150"
              :real_height="150"
              :is_more="true"
              @send_pic="onSuccess($event, 2)"
              @del_pic="edit_data.certificate_arr.splice($event, 1)"
            ></uploadpic>
          </el-col>
        </el-form-item>
        <el-form-item label="信息">
          <el-row class="mar_bottom_15">
            <el-col :span="2" class="pd_right_15">
              <el-input
                v-model="edit_data.information_title"
                placeholder="标题"
              ></el-input>
            </el-col>
            <el-col :span="12">
              <el-input
                v-model="edit_data.information_desc"
                placeholder="描述"
              ></el-input>
            </el-col>
            <el-col :span="4">
              <el-button
                :loading="$store.state.isLoading"
                type="primary"
                class="mar_lf_10"
                size="medium"
                @click="informationadd"
                >+</el-button
              >
            </el-col>
          </el-row>
          <el-col :span="24">
            <div class="lh2 size_12 sizeColor">
              PS：新增参数需要点击+按钮，才能保存成功
            </div>
          </el-col>
          <el-row
            v-for="(item, index) in edit_data.information_list"
            :key="index"
            class="mar_bottom_15"
          >
            <el-col :span="2" class="pd_right_15">
              <el-input v-model="item.title" placeholder="标题"></el-input>
            </el-col>
            <el-col :span="12">
              <el-input v-model="item.desc" placeholder="描述"></el-input>
            </el-col>
            <el-col :span="4">
              <el-button
                :loading="$store.state.isLoading"
                type="primary"
                class="mar_lf_10"
                size="medium"
                @click="edit_data.information_list.splice(index, 1)"
                >-</el-button
              >
            </el-col>
          </el-row>
        </el-form-item>

        <el-form-item>
          <el-button
            :loading="$store.state.isLoading"
            type="primary"
            @click="saveEdit(edit_data)"
            >保 存</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog
      :close-on-click-modal="false"
      title="查看"
      class="tl size_13"
      width="800px"
      :visible.sync="dialogDetailVisible"
    >
      <div class="detail_content">
        <div class="detail_title">个人介绍</div>
        <div class="detail_box">
          {{ edit_data.introduce }}
        </div>
      </div>
      <div class="detail_content">
        <div class="detail_title">个人介绍图片</div>
        <div class="detail_box">
          <el-image
            v-for="(item, i) in edit_data.introduce_piclink_arr"
            :key="i"
            fit="cover"
            style="width: 100px; height: 100px; margin-right: 15px"
            :src="item"
            :preview-src-list="edit_data.introduce_piclink_arr"
          >
          </el-image>
        </div>
      </div>
      <div class="detail_content">
        <div class="detail_title">证书图片</div>
        <div class="detail_box">
          <el-image
            v-for="(item, i) in edit_data.certificate_arr"
            :key="i"
            fit="cover"
            style="width: 100px; height: 100px; margin-right: 15px"
            :src="item"
            :preview-src-list="edit_data.certificate_arr"
          >
          </el-image>
        </div>
      </div>

      <div class="detail_content">
        <div class="detail_title">信息</div>
        <div class="detail_box">
          <div
            class="detail_information_item"
            v-for="(item, i) in edit_data.information_list"
            :key="i"
          >
            <div class="information_title">
              <el-tag>{{ item.title }}</el-tag>
            </div>
            <div class="information_dsc">{{ item.desc }}</div>
          </div>
        </div>
      </div>
    </el-dialog>
    <el-dialog
      :close-on-click-modal="false"
      title="查看区域"
      :visible.sync="dialogAreaVisible"
      class="tl size_13 dialog_no_pading"
      width="80%"
    >
      <tableComponents
        :isHavePagination="false"
        :isShow="false"
        :isHaveAdd="true"
        :isHaveExport="false"
        :navTitleShow="false"
        @toAdd="openMasterAreaAdd"
      >
        <template v-slot:table>
          <el-table
            ref="multipleTable"
            :data="masterAreaList"
            stripe
            header-row-class-name="head_color"
            tooltip-effect="dark"
            style="width: 99.8%"
          >
            <el-table-column label="标题" min-width="220">
              <template slot-scope="scope">
                <div
                  class="tab_div"
                  v-if="scope.row.region && scope.row.region.title"
                >
                  {{ scope.row.region.title }}
                </div>
                <div class="tab_div" v-else>无</div>
              </template>
            </el-table-column>
            <el-table-column label="经纬度" min-width="220">
              <template slot-scope="scope">
                <div
                  class="tab_div"
                  v-if="scope.row.region && scope.row.region.latitude"
                >
                  {{
                    scope.row.region.latitude + "," + scope.row.region.longitude
                  }}
                </div>
                <div class="tab_div" v-else>无</div>
              </template>
            </el-table-column>
            <el-table-column label="添加时间" min-width="220">
              <template slot-scope="scope">
                <div class="tab_div">
                  {{ scope.row.created_time | getTimeFormat }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="修改时间" min-width="220">
              <template slot-scope="scope">
                <div class="tab_div">
                  {{ scope.row.update_time | getTimeFormat }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="操作" min-width="120">
              <template slot-scope="scope">
                <el-row class="myblank">
                  <el-button
                    :loading="$store.state.isLoading"
                    size="mini"
                    type="danger"
                    @click="deleteMasterArea(scope.row.id)"
                    >删除</el-button
                  >
                </el-row>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </tableComponents>
    </el-dialog>
    <keep-alive>
      <component
        :is="'xzuser'"
        :show="shows"
        :isAll="false"
        showType="list"
        @sendShop="getSend"
        @isshow="getShow"
      ></component>
    </keep-alive>

    <el-dialog
      :close-on-click-modal="false"
      title="添加区域"
      class="tl size_13"
      width="800px"
      :visible.sync="masterAreaAddVisible"
    >
      <el-form :model="masterAreaForm" ref="form" label-width="120px">
        <el-form-item label="选择区域：">
          <el-select v-model="masterAreaForm.sid" placeholder="请选择区域">
            <el-option
              v-for="(item, i) in areaList"
              :key="i"
              :label="item.title"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button
            :loading="$store.state.isLoading"
            type="primary"
            @click="saveMasterAreaAdd(edit_data)"
            >保 存</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog
      :close-on-click-modal="false"
      title="查看分类"
      :visible.sync="dialogCateVisible"
      class="tl size_13 dialog_no_pading"
      width="80%"
    >
      <tableComponents
        :isHavePagination="false"
        :isShow="false"
        :isHaveAdd="true"
        :isHaveExport="false"
        :navTitleShow="false"
        @toAdd="openMasterCateAdd"
      >
        <template v-slot:table>
          <el-table
            ref="multipleTable"
            :data="masterCateList"
            stripe
            header-row-class-name="head_color"
            tooltip-effect="dark"
            style="width: 99.8%"
          >
            <el-table-column label="标题" min-width="220">
              <template slot-scope="scope">
                <div
                  class="tab_div"
                  v-if="scope.row.product_cate && scope.row.product_cate.title"
                >
                  {{ scope.row.product_cate.title }}
                </div>
                <div class="tab_div" v-else>无</div>
              </template>
            </el-table-column>

            <el-table-column label="添加时间" min-width="220">
              <template slot-scope="scope">
                <div class="tab_div">
                  {{ scope.row.created_time | getTimeFormat }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="修改时间" min-width="220">
              <template slot-scope="scope">
                <div class="tab_div">
                  {{ scope.row.update_time | getTimeFormat }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="操作" min-width="120">
              <template slot-scope="scope">
                <el-row class="myblank">
                  <el-button
                    :loading="$store.state.isLoading"
                    size="mini"
                    type="danger"
                    @click="deleteMasterCate(scope.row.id)"
                    >删除</el-button
                  >
                </el-row>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </tableComponents>
    </el-dialog>
    <el-dialog
      :close-on-click-modal="false"
      title="添加分类"
      class="tl size_13"
      width="800px"
      :visible.sync="masterCateAddVisible"
    >
      <el-form :model="masterCateForm" ref="form" label-width="120px">
        <el-form-item label="选择分类：">
          <!-- <el-select v-model="masterCateForm.sid" placeholder="请选择区域">
            <el-option v-for="(item, i) in areaList" :key="i" :label="item.title" :value="item.id"></el-option>
          </el-select> -->
          <el-cascader
            :options="cateList"
            :props="optionProps"
            :show-all-levels="false"
            change-on-select
            style="width: 100%"
            v-model="masterCateForm.sid"
            placeholder="请选择栏目"
          ></el-cascader>
        </el-form-item>

        <el-form-item>
          <el-button
            :loading="$store.state.isLoading"
            type="primary"
            @click="saveMasterCateAdd(edit_data)"
            >保 存</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import xzuser from "@/components/currency/xz_user.vue";
import uploadpic from "@/components/page/pic/up_pic";
import cityCascader from "@/components/currency/cityCascader/cityCascader";
import { receivingMasterSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  data() {
    return {
      optionProps: {
        value: "id",
        label: "title",
        children: "z",
      },
      masterCateAddVisible: false,
      cateList: [],
      masterCateForm: {},
      dialogCateVisible: false,
      masterCateList: [],
      masterCateId: "",

      masterAreaAddVisible: false,
      areaList: [],
      masterAreaForm: {},

      dialogAreaVisible: false,
      masterAreaList: [],
      masterAreaId: "",
      srcList: [],
      dialogDetailVisible: false,
      searchDataInfo: receivingMasterSearchData,
      current: "",
      shows: false,
      isEdit: false,
      dialogFormVisible: false,
      edit_data: {
        piclink: "",
      },
      tableLoading: false,
      list: [],
      pageSize: 10,
      currentPage: 1,
      searchAll: {},
      multipleSelection: [],
      czJWD: "",
      selectedOptions: [],
    };
  },
  components: {
    uploadpic,
    xzuser,
    cityCascader,
  },
  methods: {
    handleChange(value) {
      if (value) {
        for (var i = 0; i < value.length; i++) {
          if (i == 0) this.edit_data.province = value[i];
          if (i == 1) this.edit_data.city = value[i];
        }
      }
    },
    deleteMasterCate(id) {
      this.$swal({
        title: "您确定要删除这些信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          this.$api.getReceiving.del_worker_cate({ id_str: id }).then((res) => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", res.data.result, "success");
              this.openCate({ id: this.masterCateId });
            } else {
              this.$swal("删除失败！", res.data.result, "error");
            }
          });
        }
      });
    },
    saveMasterCateAdd() {
      if (this.masterCateForm.sid && this.masterCateForm.sid.length > 0) {
        var params = {
          id: this.masterCateForm.id,
          sid: this.masterCateForm.sid[this.masterCateForm.sid.length - 1],
        };

        this.$api.getReceiving.add_worker_cate(params).then((res) => {
          if (res.data.code != 200) {
            this.$swal("添加失败！", res.data.result, "error");
          } else {
            this.openCate({ id: this.masterCateId });
            this.masterCateAddVisible = false;
          }
        });
      } else {
        this.$swal("请选择分类", "", "error");
      }
    },
    openMasterCateAdd() {
      this.masterCateForm = {
        id: this.masterCateId,
        sid: [],
      };
      this.masterCateAddVisible = true;
    },
    openCate(item) {
      this.$api.getReceiving.get_worker_cate({ id: item.id }).then((res) => {
        if (res.data.code == 200) {
          this.masterCateId = item.id;
          this.masterCateList = res.data.result;
          this.dialogCateVisible = true;
        }
      });
    },
    deleteMasterArea(id) {
      this.$swal({
        title: "您确定要删除这些信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          this.$api.getReceiving.del_worker_area({ id_str: id }).then((res) => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", res.data.result, "success");
              this.openArea({ id: this.masterAreaId });
            } else {
              this.$swal("删除失败！", res.data.result, "error");
            }
          });
        }
      });
    },
    saveMasterAreaAdd() {
      var params = this.masterAreaForm;
      this.$api.getReceiving.add_worker_area(params).then((res) => {
        if (res.data.code != 200) {
          this.$swal("添加失败！", res.data.result, "error");
        } else {
          this.openArea({ id: this.masterAreaId });
          this.masterAreaAddVisible = false;
        }
      });
    },
    openMasterAreaAdd() {
      this.masterAreaForm = {
        id: this.masterAreaId,
        sid: "",
      };
      this.masterAreaAddVisible = true;
    },
    openArea(item) {
      this.$api.getReceiving.get_worker_area({ id: item.id }).then((res) => {
        if (res.data.code == 200) {
          this.masterAreaId = item.id;
          this.masterAreaList = res.data.result;
          this.dialogAreaVisible = true;
        }
      });
    },
    openOrder(item) {
      let routeData = this.$router.resolve({
        path: "/index/order",
        query: { receiving_uid: item.id },
      });
      window.open(routeData.href, "_blank");
    },
    informationadd() {
      if (!this.edit_data.information_title) {
        this.$message.error("请输入标题");
      } else if (!this.edit_data.information_desc) {
        this.$message.error("请输入描述");
      } else {
        this.edit_data.information_list.push({
          title: this.edit_data.information_title,
          desc: this.edit_data.information_desc,
        });
        this.edit_data.information_title = "";
        this.edit_data.information_desc = "";
      }
    },
    getShow(val) {
      this.shows = val;
    },
    getSend(info) {
      this.edit_data.username = info.username;
      this.edit_data.uid = info.id;
    },
    xzshop(val) {
      this.current = val;
      this.shows = true;
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    moreDelete() {
      //批量删除
      var str = "";
      if (this.multipleSelection.length <= 0) {
        this.$message.error("未选择批量删除");
      } else {
        for (var i in this.multipleSelection) {
          str += this.multipleSelection[i].id + "@";
        }
        str = str.slice(0, -1);
        this.$swal({
          title: "您确定要删除这些信息吗",
          text: "删除后将无法恢复，请谨慎操作！",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "是的，我要删除",
          cancelButtonText: "容我三思",
        }).then((willDelete) => {
          if (willDelete.value) {
            this.$api.getReceiving
              .del_receiving_master({ id_str: str })
              .then((res) => {
                if (res.data.code == 200) {
                  this.$swal("删除成功！", res.data.result, "success");
                  this.getNewsAll();
                } else {
                  this.$swal("删除失败！", res.data.result, "error");
                }
              });
          }
        });
      }
    },
    openDelete(id) {
      //删除
      this.$swal({
        title: "您确定要删除这些信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          this.$api.getReceiving
            .del_receiving_master({ id: id })
            .then((res) => {
              if (res.data.code == 200) {
                this.$swal("删除成功！", res.data.result, "success");
                this.getNewsAll();
              } else {
                this.$swal("删除失败！", res.data.result, "error");
              }
            });
        }
      });
    },

    openAdd() {
      this.edit_data = {
        introduce_piclink_arr: [],
        certificate_arr: [],
        information_list: [],
        information_title: "",
        information_desc: "",
        avatar: "",
      };
      this.isEdit = false;
      this.dialogFormVisible = true;
    },
    openDetail(item) {
      let form = JSON.parse(JSON.stringify(item));
      if (form.information) {
        form.information_list = JSON.parse(form.information);
      } else {
        form.information_list = [];
      }
      if (form.introduce_piclink) {
        form.introduce_piclink_arr = [];
        JSON.parse(form.introduce_piclink).forEach((item, i) => {
          form.introduce_piclink_arr.push(item.piclink);
        });
      } else {
        form.introduce_piclink_arr = [];
      }
      if (form.certificate) {
        form.certificate_arr = [];
        JSON.parse(form.certificate).forEach((item, i) => {
          form.certificate_arr.push(item.piclink);
        });
      } else {
        form.certificate_arr = [];
      }
      this.edit_data = JSON.parse(JSON.stringify(form));
      this.dialogDetailVisible = true;
    },
    openEdit(item) {
      this.isEdit = true;

      let form = JSON.parse(JSON.stringify(item));
      if (form.birthday) {
        form.birthday = form.birthday * 1000;
      }
      if (form.employment) {
        form.employment = form.employment * 1000;
      }
      if (form.information) {
        form.information_list = JSON.parse(form.information);
      } else {
        form.information_list = [];
      }
      if (form.introduce_piclink) {
        form.introduce_piclink_arr = JSON.parse(form.introduce_piclink);
      } else {
        form.introduce_piclink_arr = [];
      }
      if (form.certificate) {
        form.certificate_arr = JSON.parse(form.certificate);
      } else {
        form.certificate_arr = [];
      }
      form.information_title = "";
      form.information_desc = "";
      this.czJWD = form.cz_latitude + "," + form.cz_longitude;
      this.selectedOptions = [form.province, form.city];
      this.edit_data = JSON.parse(JSON.stringify(form));
      this.dialogFormVisible = true;
    },
    onSuccess(pic, val) {
      if (val == 1) {
        this.edit_data.introduce_piclink_arr =
          this.edit_data.introduce_piclink_arr.concat(pic);
      } else if (val == 2) {
        this.edit_data.certificate_arr =
          this.edit_data.certificate_arr.concat(pic);
      } else if (val == 4) {
        this.edit_data.cardid1 = pic;
      } else if (val == 5) {
        this.edit_data.cardid2 = pic;
      } else {
        this.edit_data.avatar = pic;
      }
    },

    receive_search(obj) {
      this.currentPage = 1;
      this.searchAll = obj;
      this.getNewsAll();
    },
    handleSwitch(val, item) {
      var params = item;
      params.show = val;
      this.$api.getReceiving.edit_receiving_master(params).then((res) => {
        if (res.data.code != 200) {
          this.$swal("编辑失败！", res.data.result, "error");
          this.getNewsAll();
        }
      });
    },

    sorta(a, b) {
      return b - a;
    },
    sortNew(index, item) {
      var params = item;
      params.sort = item.sort;
      this.$api.getReceiving.edit_receiving_master(params).then((res) => {
        if (res.data.code == 200) {
          return;
        } else {
          this.$swal("编辑失败！", res.data.result, "error");
          this.getNewsAll();
        }
      });
    },
    saveEdit(item) {
      var params = {};
      params = JSON.parse(JSON.stringify(item));

      if (this.czJWD) {
        var jwd_ar = this.czJWD.split(",");
        params.cz_longitude = jwd_ar[1]; //经度
        params.cz_latitude = jwd_ar[0]; //纬度
      }

      if (params.birthday) {
        params.birthday = params.birthday / 1000;
      } else {
        params.birthday = "";
      }
      if (params.employment) {
        params.employment = params.employment / 1000;
      } else {
        params.employment = "";
      }
      params.information = JSON.stringify(params.information_list);
      delete params.information_list;
      params.introduce_piclink = JSON.stringify(params.introduce_piclink_arr);
      delete params.introduce_piclink_arr;
      params.certificate = JSON.stringify(params.certificate_arr);
      delete params.certificate_arr;

      if (this.isEdit == false) {
        this.$api.getReceiving.add_receiving_master(params).then((res) => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.currentPage = 1;
            this.getNewsAll();
            this.$swal("添加成功！", res.data.result, "success");
          } else {
            this.$swal("添加失败！", res.data.result, "error");
          }
        });
      } else {
        this.$api.getReceiving.edit_receiving_master(params).then((res) => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.getNewsAll();
            this.$swal("编辑成功！", res.data.result, "success");
          } else {
            this.$swal("编辑失败！", res.data.result, "error");
          }
        });
      }
    },
    getNewsAll() {
      this.tableLoading = true;
      var params = {};
      params = JSON.parse(JSON.stringify(this.searchAll));
      params.page = this.currentPage || 1;
      params.page_size = this.pageSize || "";
      params.is_check = 1;
      if (this.$route.query.id) {
        params.id = this.$route.query.id;
      }
      for (var i in params) {
        if (!params[i]) {
          params[i] = "";
        }
      }
      var query = JSON.parse(JSON.stringify(this.queryObj || {}));
      var obj = Object.assign(query, params);
      this.$api.getReceiving.get_receiving_master(obj).then((res) => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        setTimeout(() => {
          this.tableLoading = false;
        }, 200);
      });
    },
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSize = val;
      this.getNewsAll();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getNewsAll();
    },
  },
  created() {
    if (this.$route.query) {
      this.queryObj = this.$route.query;
      if (this.$route.query.page) {
        this.currentPage = this.$route.query.page;
        delete this.queryObj.page;
      }
    }
    this.getNewsAll();

    this.$api.getReceiving.get_receiving_area({}).then((res) => {
      if (res.data.code == 200) {
        this.areaList = res.data.result;
      }
    });

    this.$api.getShops.getProductCateTreeList({ parent_id: "" }).then((res) => {
      if (res.data.code == 200 && res.data.status == 1 && res.data.result) {
        this.cateList = res.data.result;
      }
    });
  },
  computed: {},
};
</script>

<style lang="less" scoped>
.myblank button {
  margin: 5px 5px 0 0;
}
.detail_content {
  width: 100%;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  margin-bottom: 20px;
  .detail_title {
    width: 120px;
    font-size: 12px;
    color: #626262;
    font-weight: bold;
    margin-right: 10px;
  }
  .detail_box {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    font-size: 14px;
    color: #626262;
    .detail_information_item {
      width: 100%;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      margin-bottom: 15px;
      .information_title {
        width: 120px;
      }
    }
  }
}
/deep/.dialog_no_pading .el-dialog__body {
  padding-top: 0;
}
</style>
